import predictionio as pio

app_name = 'xiaoma'
access_key = 'WZ5c5YFMsmUTNlIkQgSL29T6xDAD4oUw6sqmqpshwmjm2rjRIqc-w7kXp8ACId09'
url = 'http://xiaoma01:7070'
client = None


def create_client():
    return pio.EventClient(
        access_key=access_key,
        url=url,
        threads=5,
        qsize=500
    )


def event(userId, itemId, rate):
    global client
    if not client:
        client = create_client()

    client.create_event(
        event="rate",
        entity_type="user",
        entity_id=userId,
        target_entity_type="item",
        target_entity_id=itemId,
        properties={"rating": float(rate)}
    )


if __name__ == '__main__':
    pass
